'use strict';

$(document).ready(function () {
var isNullForForm1 = false;
var isNullForForm2 = false;
var isNullForForm3 = false;
    $('#wizard').steps({
        headerTag: 'h3',
        bodyTag: 'section',
        autoFocus: true,
        titleTemplate: '#index# #title#',
        onStepChanging: function (event, currentIndex, newIndex) {
            if (currentIndex < newIndex) {
                var form = document.getElementById('form1');

                if (currentIndex === 0) {
                    $(form).find("input[required]").each(function () {
                        var id = "#"+$(this).attr("id");
                        if(validationNull(id)){
                            isNullForForm1 = true;
                        }
                        if(id == "#fprice"){
                                if(validationNumAndDecimal(id,false,'b')){
                                    isNullForForm1 = true;
                                }
                        }
                    });
                    if (isNullForForm1) {
                        event.preventDefault();
                        event.stopPropagation();
                        isNullForForm1 = false;
                    } else {
                        return true;
                    }
                } else if (currentIndex === 1) {
                    var f;
                    $("#face,#view,#detail").each(function (i) {
                        f = $(this).find(".dz-image").html();
                        if(f == undefined){
                            if(i == 0){
                                swal("您还未上传商品的 展示图片 哦！", {
                                    icon: "warning"
                                });
                            }else if(i == 1){
                                swal("您还未上传商品的 浏览图片 哦！", {
                                    icon: "warning"
                                });
                            }else {
                                swal("您还未上传描述商品的 详情图片 哦！", {
                                    icon: "warning"
                                });
                            }
                            isNullForForm2 = true;
                            return false;
                        }
                    });
                    if (isNullForForm2) {
                        event.preventDefault();
                        event.stopPropagation();
                        isNullForForm2 = false;
                    } else {
                        return true;
                    }
                } else {
                    return true;
                }
            } else {
                return true;
            }
        },
        onStepChanged:function(){
            $('.wizard li[aria-disabled = "false"] a').css("color","white");
            $('.wizard li[aria-disabled = "true"] a').css("color","");
        },
        onFinishing:function () {
            $("#FKForms").find("input[required]").each(function () {
                var id = "#"+$(this).attr("id");
                if(validationNull(id)){
                    isNullForForm3 = true;
                }
            });

            $("#FKForms").find("input[name = 'fkname']").each(function () {
                var id = $(this).attr("id");
                if(validationExist($(this).attr("id"))){
                    isNullForForm3 = true;
                }
            });

            $("#FKForms").find("input[name = 'fkprice']").each(function () {
                var id = "#"+$(this).attr("id");
                    if(validationNumAndDecimal(id,false,'b')){
                        isNullForForm3 = true;
                    }
            });

            var f;
            $("#FKForms").find(".dropzone").each(function (i) {
                f = $(this).find(".dz-image").html();
                if(f == undefined){
                        swal("您还未上传 颜色种类"+(i+1)+" 的展示图片哦！", {
                            icon: "warning"
                        });
                    isNullForForm3 = true;
                    return false;
                }
            });

            if (isNullForForm3) {
                event.preventDefault();
                event.stopPropagation();
                isNullForForm3 = false;
                return false;
            } else {
                return true;
            }
        },
        onFinished:function () {
            myInsert();
        }

    });

});

